//
//  RewardVideoVC.m
//  CJModileAdDemo
//
//  Created by JUN on 2022/3/6.
//

#import "RewardVideoVC.h"
#import "CustomShowView.h"
#import <BUAdSDK/BUAdSDK.h>

@interface RewardVideoVC ()<BUNativeExpressRewardedVideoAdDelegate>

@property (nonatomic,strong) BUNativeExpressRewardedVideoAd *byte_rewardVideoAd;

@end

@implementation RewardVideoVC

@synthesize customView = _customView;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)dealloc
{
    NSLog(@"事件:%s", __FUNCTION__);
}
 
- (void)loadAdData {
    BURewardedVideoModel *model = [[BURewardedVideoModel alloc] init];
    model.userId = @"byte_1234";
    BUNativeExpressRewardedVideoAd *rewardAd = [[BUNativeExpressRewardedVideoAd alloc] initWithSlotID:@"103566595" rewardedVideoModel:model];
    rewardAd.delegate = self;
    [rewardAd loadAdData];
    self.byte_rewardVideoAd = rewardAd;
}

- (void)setupUI {
    self.title = @"RewardVideoAd";
    [self.view addSubview:self.customView];
    self.customView.frame = CGRectMake(0, 100, 200, 200);
    self.customView.center = self.view.center;
}

- (void)handleEvent:(NSInteger)eve {
    if (eve == 0) {
        [self loadAdData];
        return;
    }
}

- (CustomShowView *)customView {
    if (!_customView) {
        _customView = [[CustomShowView alloc] init];
        __weak RewardVideoVC *weakSelf = self;
        _customView.event = ^(NSInteger eve) {
            [weakSelf handleEvent:eve];
        };
    }
    return _customView;
}

#pragma mark CJRewardVideoAdDelegate
- (void)nativeExpressRewardedVideoAdDidLoad:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
    [rewardedVideoAd showAdFromRootViewController:self];
}

- (void)nativeExpressRewardedVideoAd:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd didFailWithError:(NSError *_Nullable)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressRewardedVideoAdServerRewardDidSucceed:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd verify:(BOOL)verify {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressRewardedVideoAdServerRewardDidFail:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressRewardedVideoAdDidVisible:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressRewardedVideoAdDidClose:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressRewardedVideoAdDidClick:(BUNativeExpressRewardedVideoAd *)rewardedVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}
@end
